package nix.demo6.web.filter;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/**
 *  HttpServletRequestWrapper是HttpServletRequest接口用于装饰的实现类
 *  接口实现式装饰 ——> 继承式装饰
 */
public class EncodingRequest extends HttpServletRequestWrapper {

	private HttpServletRequest request;

	public EncodingRequest(HttpServletRequest request) {
		super(request);
		this.request = request;
	}

	@Override
	public String getParameter(String name) {
		// 增强getParameter方法，处理GET请求编码问题
		String value = this.request.getParameter(name);
		try {
			value = new String(value.getBytes("ISO-8859-1"), "utf-8");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
		return value;
	}
}
